package com.Hsu.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author Hsu琛君珩
 * @ClassName:AspectDemo
 * @date 2024-01-16
 * @apiNote
 * @Version: v1.0
 */

@Slf4j
//@Component
@Aspect
public class AspectDemo {
    @Pointcut("execution(* com.Hsu.demo.controller.*.*(..))")
    public void pt() {//定义切点，叫pt
    }

    @Before("pt()")
    public void doBefore() {
        log.info("执行Aspect Before");
    }

    @After("pt()")
    public void doAfter() {
        log.info("执行Aspect After");
    }

    @AfterReturning("pt()")
    public void doAfterReturning() {
        log.info("执行Aspect AfterReturning");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("执行Aspect AfterThrowing");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("执行Aspect Around 前");
        Object result = joinPoint.proceed();
        log.info("执行Aspect Around 后");
        return result;
    }
}